package unimelb.filesync.common.message;

public class NetworkMessage {

    public static final String TYPE_REQUEST_BLOCK_SIZE_ROLE = "RequestBlockSizeRole";

    public static final String TYPE_RESPONSE_BLOCK_SIZE_ROLE = "ResponseBlockSizeRole";

    public static final String TYPE_FILE_SYNC_REQUEST = "FileSyncRequest";

    public static final String TYPE_NEW_BLOCK_REQUEST = "RequestNewBlock";

    public static final String TYPE_SEQUENCE_COMPLETE = "SequenceComplete";

    public static final String TYPE_REQUEST_PUBLIC_KEY = "RequestPublicKey";

    public static final String TYPE_RESPONSE_PUBLIC_KEY = "ResponsePublicKey";

    public static final String TYPE_SECRET_KEY_MSG = "SecretKeyMsg";

    public static final String TYPE_PASSWORD_MSG = "PasswordMsg";

    private final String type;

    private final Object content;

    private NetworkMessage(String type, Object content) {
        super();
        this.type = type;
        this.content = content;
    }

    public String getType() {
        return type;
    }

    @SuppressWarnings("unchecked")
    public <T extends Jsonable> T getContent() {
        return (T) content;
    }

    public static NetworkMessage createBlockSizeRoleRequestMsg(Object content) {
        return new NetworkMessage(TYPE_REQUEST_BLOCK_SIZE_ROLE, content);
    }

    public static NetworkMessage createBlockSizeRoleResponseMsg(Object content) {
        return new NetworkMessage(TYPE_RESPONSE_BLOCK_SIZE_ROLE, content);
    }

    public static NetworkMessage createFileSyncRequestMsg(Object content) {
        return new NetworkMessage(TYPE_FILE_SYNC_REQUEST, content);
    }

    public static NetworkMessage createNewBlockRequestMsg(Object content) {
        return new NetworkMessage(TYPE_NEW_BLOCK_REQUEST, content);
    }

    public static NetworkMessage createSequenceCompleteMsg(Object content) {
        return new NetworkMessage(TYPE_SEQUENCE_COMPLETE, content);
    }

    public static NetworkMessage createPublicKeyRequestMsg(Object content) {
        return new NetworkMessage(TYPE_REQUEST_PUBLIC_KEY, content);
    }

    public static NetworkMessage createPublicKeyResponseMsg(Object content) {
        return new NetworkMessage(TYPE_RESPONSE_PUBLIC_KEY, content);
    }

    public static NetworkMessage createSecretKeyMsg(Object content) {
        return new NetworkMessage(TYPE_SECRET_KEY_MSG, content);
    }

    public static NetworkMessage createPasswordMsg(Object content) {
        return new NetworkMessage(TYPE_PASSWORD_MSG, content);
    }
}
